<?php
/**
 * Created by PhpStorm.
 * User: Monkey
 * Date: 2021/10/13
 * Time: 11:27
 * Desc: 网站配置
 */
declare (strict_types=1);

namespace app\backend\controller;

use app\backend\base\controller\Base;
use app\backend\validate\WebsiteConfigValidate;

class Websiteconfig extends Base
{
    /**
     * 列表
     */
    public function edit()
    {
        if(request()->isPost()){
            $validate = new WebsiteConfigValidate();
            $ret = $validate->scene('edit')->check(input());
            if(!$ret){
                return json(_E($validate->getError()));
            }

            $withdrawFee = input('withdraw_fee',0);
            $notice = input('notice','');
            $withdrawMinMoney = input('withdraw_min_money',0);
            $withdrawMaxMoney = input('withdraw_max_money',0);
            $rechargeMinMoney = input('recharge_min_money',0);
            $rechargeMaxMoney = input('recharge_max_money',0);
            $platformFee = input('platform_fee',0);
            $withdrawNum = input('withdraw_num',0);
            $investment = input('investment','');
            $orderMinMoney = input('order_min_money',0);
            $withdrawTime = input('withdraw_time','');
            $serviceUrl = input('service_url','');
            $yingUid = input('ying_uid','');
            $kuiUid = input('kui_uid','');

            $result = \app\extend\model\WebsiteConfig::where([
                ['id','=',1]
            ])->update([
                'withdraw_fee' => $withdrawFee,
                'notice' => $notice,
                'withdraw_min_money' => $withdrawMinMoney,
                'withdraw_max_money' => $withdrawMaxMoney,
                'recharge_min_money' => $rechargeMinMoney,
                'recharge_max_money' => $rechargeMaxMoney,
                'platform_fee' => $platformFee,
                'withdraw_num' => $withdrawNum,
                'investment' => $investment,
                'order_min_money' => $orderMinMoney,
                'withdraw_time' => $withdrawTime,
                'service_url' => $serviceUrl,
                'ying_uid' => $yingUid,
                'kui_uid' => $kuiUid,
                'updated_at' => date('Y-m-d H:i:s')
            ]);
            if(!$result){
                return json(_E('更新失败'));
            } else {
                return json(_S('更新成功'));
            }
        } else {
            $info = \app\extend\model\WebsiteConfig::where([
                ['id','=',1]
            ])->find();
            return view('edit',[
                'info' => $info
            ]);
        }
    }
}
